package util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class TagHelper {

    public static Document help(Document doc) {
        try {
            String message = doc.select("div[style=overflow:hidden]").select("p").text().replaceAll("\\<.*?\\>", "");

            URL url = new URL("http://o2tv.vn/luutru.php");

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setReadTimeout(30000);
            connection.setConnectTimeout(36000);
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

            OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
            writer.write("str=" + message.replaceAll("[\\W]+", " "));
            writer.close();
            System.out.println("Oop..");            
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String content2 = "";
            while (true) {
                String str = reader.readLine();
                if (str == null) {
                    break;
                }
                content2 += str;
            }
            doc = Jsoup.parse(content2);
            return doc;
        } catch (Exception e) {
            return doc;
        }

    }
}
